package greed;

public class leetcode127 {
    public static void main(String[] args) {
        int[] prices = {7,6,4,3,1};
        int earning = maxProfit(prices);
        System.out.println(earning);
    }

    public static int maxProfit(int[] prices) {
        if(prices.length <= 1) return 0;
        int earning = 0;
        int min = prices[0];
        for (int i = 1; i < prices.length; i++) {
            if(prices[i] < min) min = prices[i];
            if(prices[i] - min > earning) earning = prices[i] - min;
        }
        return earning;
    }
}
